package com.hopes.bizz.protocol.hj212.log;

import com.hopes.bizz.protocol.hj212.entity.ProtocolHj212PacketLogEntity;
import com.hopes.bizz.protocol.hj212.entity.ProtocolHj212MqLogEntity;
import com.hopes.bizz.protocol.hj212.service.ProtocolHj212PacketLogService;
import com.hopes.bizz.protocol.hj212.service.ProtocolHj212MqLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author daijie
 * @version 1.0
 * @date 2023/6/8 11:17
 * @Description:
 */
@Component
public class ProtocolLogger {
    @Autowired
    private ProtocolHj212MqLogService mqLogService;
    @Autowired
    private ProtocolHj212PacketLogService packetLogService;

    public void saveHj212PacketLog(String original, Date receiveTime, Boolean handlerResult,
                                   String handlerDetail, String handlerData, Integer handlerTime) {
        ProtocolHj212PacketLogEntity packetLog = new ProtocolHj212PacketLogEntity();
        packetLog.setOriginal(original);
        packetLog.setReceiveTime(receiveTime);
        packetLog.setHandlerResult(handlerResult);
        packetLog.setHandlerDetail(handlerDetail);
        packetLog.setHandlerData(handlerData);
        packetLog.setHandlerTime(handlerTime);

        packetLogService.save(packetLog);
    }

    public void saveHj212MqLog(Boolean success, String textMessage, Date sendTime, String queue, String topic,
                               Integer deliveryMode, Integer acknowledgeMode, String errorCode, String detailMessage) {
        ProtocolHj212MqLogEntity mqLog = new ProtocolHj212MqLogEntity();
        mqLog.setSuccess(success);
        mqLog.setTextMessage(textMessage);
        mqLog.setSendTime(sendTime);
        mqLog.setQueue(queue);
        mqLog.setTopic(topic);
        mqLog.setDeliveryMode(deliveryMode);
        mqLog.setAcknowledgeMode(acknowledgeMode);
        mqLog.setErrorCode(errorCode);
        mqLog.setDetailMessage(detailMessage);

        mqLogService.save(mqLog);
    }
}
